<template>
  <view class="container">
    <image :src="'https://prayer.jiangkukeji.cn' + logo" class="logo" mode="aspectFill"></image>
    <button class="btn" open-type="getPhoneNumber" @getphonenumber="phonelogin">授权登录</button>
    <view @click="login">临时登录</view>
    <!-- 用户阅读协议 -->
    <view class="box">
      <radio value="check" :checked="check" @click="check = !check" style="transform: scale(0.7)" color="#ffc2d5" />
      <view>
        请先阅读
        <text @click="gouserxieyi" style="color: blue">《用户协议》</text>
        和
        <text @click="goyinsixieyi" style="color: blue">《隐私政策》</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { getCurrentInstance, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
const proxy = getCurrentInstance().appContext.config.globalProperties;
const http = proxy.$http;
// 是否阅读协议
const check = ref(false);

// 用户手机号一键登录
const code = ref(''); // logincode
const phonecode = ref(''); //phonecode
const phonelogin = (e) => {
  console.log(e.detail.code);
  if (!check.value) {
    return uni.showToast({
      title: '请先阅读协议',
      icon: 'none'
    });
  }
  // 调登录的接口
  uni.login({
    provider: 'weixin',
    success: (res) => {
      console.log('login的code', res);
      http('/user/weChatMiniLogin', { code: e.detail.code }, 'POST');
    }
  });
};

// 临时登录
const login = async () => {
  const res = await http('/user/mobileLogin', { mobile: '13211111111', code: '6666' }, 'POST');
  console.log('登录的结果', res.data);
  if (res.code == 1) {
    uni.setStorageSync('token', res.data.userinfo.token);
    uni.reLaunch({
      url: '/pages/index/index'
    });
  }
};

// 获取logo
const logo = ref('');
const getLogo = async () => {
  const res = await http('/user/getSetRes', {}, 'POST');
  console.log(res.data);
  logo.value = res.data.logo;
};

// 跳转到用户协议
const gouserxieyi = () => {
  uni.navigateTo({
    url: '/pages/userxieyi/userxieyi'
  });
};

// 跳转到隐私协议
const goyinsixieyi = () => {
  uni.navigateTo({
    url: '/pages/yinsixieyi/yinsixieyi'
  });
};

onLoad(() => {
  getLogo();
});
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  .logo {
    width: 260rpx;
    height: 260rpx;
    margin: 161rpx 245rpx;
    background: #ffcedd;
    border-radius: 35rpx;
  }
  .btn {
    box-sizing: border-box;
    width: 620rpx;
    height: 92rpx;
    text-align: center;
    line-height: 92rpx;
    font-family: PingFang SC;
    font-weight: bold;
    font-size: 36rpx;
    background: #ffc2d5;
    border-radius: 46rpx;
  }
  .box {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24rpx;
    margin-top: 50rpx;
  }
}
</style>
<style>
page {
  background-color: #fff;
}
</style>
